import {action} from "adajs";
import HospitalList from "./../../../controls/lists/hospital";
import VisitList from "./../../../controls/lists/visit";
import SurviveList from "./../../../controls/lists/survive";
import SearchBox from "./../../../controls/detail/searchbox";
import TabService from "./../../tabservice";
import Page from "../../../lib/page";

class LodgeService extends TabService {
    defaultData() {
        let info = {
            tabs: [
                {
                    "name": "住院管理", active: true, type: SearchBox, option: {
                        keywordName: "ltzxm",
                        list: {
                            url: "/api/admin/lgb/hospitalization/queryPage",
                            type: HospitalList
                        }
                    }
                },
                {
                    "name": "住院看望", active: false, type: SearchBox, option: {
                        keywordName: "ltzxm",
                        list: {
                            url: "/api/admin/lgb/consolation/queryPage?zflx=0",
                            method: "get",
                            type: VisitList
                        }
                    }
                },
                {
                    "name": "遗属信息", active: false, type: SearchBox, option: {
                        list: {
                            url: "/api/admin/lgb/oldperson/testament/list",
                            type: SurviveList
                        }
                    }
                }
            ],
            btns: []
        };
        this.setTabs(info.tabs);
        if (info.tabs[0].active) {
            info.btns = [{action: "adde", icon: ":for-add"}];
        }
        if (info.tabs[1].active) {
            info.btns = [{action: "add", icon: ":for-add"}];
        }
        return info;
    }

    onupdate(current, data) {
        Object.assign(current, data);
    }

    @action("setTab")
    setTab(current, name) {
        Page.set(name);
        if (name === '住院管理') {
            current.btns = [{action: "adde", icon: ":for-add"}];
        } else if (name === '住院看望') {
            current.btns = [{action: "add", icon: ":for-add"}];
        } else {
            current.btns = [];
        }
    }
}

export default LodgeService;